home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / hdf / unix / hdf3_2r2.lha / HDF3.2r2 / util / ristosds.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-10-28  |  5.5 KB  |  213 lines

  1. /***************************************************************************
  2. *
  3. *
  4. *                         NCSA HDF version 3.2r2
  5. *                            October 30, 1992
  6. *
  7. * NCSA HDF Version 3.2 source code and documentation are in the public
  8. * domain.  Specifically, we give to the public domain all rights for future
  9. * licensing of the source code, all resale rights, and all publishing rights.
  10. *
  11. * We ask, but do not require, that the following message be included in all
  12. * derived works:
  13. *
  14. * Portions developed at the National Center for Supercomputing Applications at
  15. * the University of Illinois at Urbana-Champaign, in collaboration with the
  16. * Information Technology Institute of Singapore.
  17. *
  18. * THE UNIVERSITY OF ILLINOIS GIVES NO WARRANTY, EXPRESSED OR IMPLIED, FOR THE
  19. * SOFTWARE AND/OR DOCUMENTATION PROVIDED, INCLUDING, WITHOUT LIMITATION,
  20. * WARRANTY OF MERCHANTABILITY AND WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE
  21. *
  22. ****************************************************************************
  23. */
  24.  
  25. #ifdef RCSID
  26. static char RcsId[] = "@(#)$Revision: 1.2 $";
  27. #endif
  28. /*
  29. $Header: /hdf/hdf/v3.2r2/util/RCS/ristosds.c,v 1.2 1992/07/15 21:48:48 sxu beta koziol $
  30.  
  31. $Log: ristosds.c,v $
  32.  * Revision 1.2  1992/07/15  21:48:48  sxu
  33.  *  Added changes for CONVEX
  34.  *
  35.  * Revision 1.1  1992/06/09  17:36:25  mfolk
  36.  * Initial revision
  37.  *
  38. */
  39.  
  40. /* This program converts a series raster image hdf files into   */
  41. /* a single 3D sds hdf file. Each ris hdf file contains one     */
  42. /* or more raster images. All images should be of the same      */
  43. /* dimension sizes. And, if there is a palette associated to    */
  44. /* the images, the palette should be included in the first      */
  45. /* ris file. Any subsequent palettes will be ignored.           */
  46. /* Sept. 23, 1991                        */
  47.  
  48. /*   USAGE: ristosds infile{ infile} -o outfile            */
  49.  
  50.  
  51. #include "hdf.h"
  52.  
  53. #define r_imgae 2;
  54. #define r_sds   3;
  55. #define USAGE "ristosds infile{ infile} -o outfile"
  56.  
  57. int main
  58.   PROTO((int, char **));
  59. int cntimage
  60.   PROTO((char *filename, int32 *p_w, int32 *p_h, int *n_images));
  61.  
  62.  
  63. #ifdef PROTOTYPE
  64. main(int argc, char *argv[])
  65. #else
  66. main(argc, argv)
  67.     int argc;
  68.     char *argv[];
  69. #endif /* PROTOTYPE */
  70. {
  71.  
  72.     int i,j;
  73.     int nimg, nimg0;  /* nimg, nimg0 -- number of images    */
  74.     int32 w,h;        /* w, h -- width and height of images */
  75.     int  ret, n_infile, getoutfile, ispal, dimsizes[3];
  76.     char *infile, *outfile, **argv_infile;
  77.     uint8 *indata, *indata0, palette[768];
  78.     float32 *outdata, *outdata0;
  79.  
  80.  
  81.     if (argc < 4) {
  82.     printf("Usage %s.\n", USAGE);
  83.     finishing();
  84.     }
  85.     /* initialization    */
  86.  
  87.     nimg = 0;
  88.     w = h = 0;
  89.     n_infile = 0;        /* count number of input files   */    
  90.     getoutfile = 0;
  91.     argv_infile = &argv[1];    /* save start address of input file names. */
  92.  
  93.     /* Count total number of images to be converted.   */
  94.  
  95.     while (--argc > 1)       {   /* reach -o. go to get output file name */
  96.     infile = *++argv;
  97.     if (infile[0] == '-')   {
  98.         getoutfile = 1;
  99.         break;
  100.     }
  101.     else            {
  102.             n_infile++;
  103.         ret = cntimage(infile, &w, &h, &nimg);
  104.         if (ret != 0) finishing();
  105.     }
  106.     }
  107.  
  108.     nimg0 = nimg;
  109.     printf("Total number of images: %d.\n", nimg);    
  110.  
  111.     /* get output file name     */
  112.  
  113.     argc--;
  114.  
  115.     if (getoutfile == 0 || argc < 1)      {   /* is -o or outfile missing?    */
  116.     printf("Bad commend line. \n\n\t\t %s\n", USAGE);
  117.     finishing();
  118.     }
  119.  
  120.     outfile = *++argv;
  121.     
  122.     /* read in images from all input files.      */
  123.  
  124.     outdata0 = outdata = (float32 *)malloc(nimg*w*h*(sizeof(float32)));
  125.     indata0 = indata = (uint8 *)malloc(w*h*sizeof(char));
  126.     infile = *argv_infile;
  127.     ret = DFR8getdims(infile, &w, &h, &ispal);
  128.     if (ispal) {
  129.     DFPgetpal(infile, (char *) palette);
  130.      DFR8restart();        /* in case the palette is not at the  */
  131.                 /* beginning of the first input file  */
  132.        DFPputpal(outfile, (char *)palette, 0, "a");
  133.     }
  134.     while (nimg > 0)    {
  135.     indata = indata0;    /* Restart from the beginning of the buf */
  136.     ret = DFR8getimage(infile, indata, w, h, palette);
  137.     if (ret != 0 )    {    /* end of file. open next one   */
  138.      n_infile--;
  139.         if (n_infile < 1)     {
  140.         printf("Inconsistent number of files and images\n");
  141.         finishing();
  142.         }
  143.         infile = *++argv_infile;
  144.         ret = DFR8getimage(infile, indata, w, h, palette);
  145.             if (ret != 0) finishing();
  146.     }
  147.     
  148.     /* convert image data into floating point and store in the array  */
  149.  
  150.     for (i=0; i<w; i++)
  151.         for (j=0; j<h; j++) *outdata++ = (float32) *indata++;
  152.     nimg--;
  153.     }
  154.  
  155.     dimsizes[0] = nimg0;
  156.     dimsizes[1] = w;
  157.     dimsizes[2] = h;
  158.     ret = DFSDadddata(outfile, 3, dimsizes, outdata0);
  159.     if (ret != 0) finishing();
  160.     exit(0);
  161. }
  162.  
  163.  
  164.  
  165. int finishing()    
  166. {
  167.     printf("end of ristosds.\n");
  168.     exit(1);
  169.  
  170.  
  171. /* count # of images  */
  172.          
  173. #ifdef PROTOTYPE
  174. int cntimage(char *filename, int32 *p_w, int32 *p_h, int *n_images)
  175. #else
  176. int cntimage(filename, p_w, p_h, n_images)  
  177.     char *filename;        
  178.     int32 *p_w, *p_h; /* p_w -- pointer to width   */
  179.     int *n_images;  
  180. #endif /* PROTOTYPE */
  181.  
  182. {     int32 ret, width, height;
  183.       int ispal, dimerror;
  184.  
  185.     dimerror = 0;
  186.  
  187.     ret = DFR8getdims(filename,&width, &height, &ispal);    
  188.     if (ret == FAIL)    {
  189.         HEprint(stderr, 0);
  190.         finishing();
  191.     }
  192.     if (*p_w == 0 && *p_h == 0)    {    /* the first time  */
  193.        *p_w = width;
  194.        *p_h = height;
  195.     }
  196.     while (ret == 0)    {   /* count # of images and check dims    */
  197.         if ((width != *p_w) || (height != *p_h))    {
  198.         printf("Inconsistent dims: %s .\n", filename);
  199.         dimerror = -1;
  200.         break;
  201.         } 
  202.         *n_images = *n_images + 1;
  203.         ret = DFR8getdims(filename, &width, &height, &ispal);
  204.     }
  205.  
  206.     /* ready to return   */
  207.  
  208.     DFR8restart();    
  209.     if (dimerror == -1) return(-1);
  210.     else     return(0);
  211. }
  212.